package cn.com.cmbc.config;

import com.zaxxer.hikari.HikariDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

//@MapperScan(value = "cn.com.cmbc",sqlSessionTemplateRef = "phoenixSqlSessionTemplate",sqlSessionFactoryRef = "phoenixSqlSessionFactory")
@MapperScan(value = "cn.com.cmbc")
@Configuration
public class PhoenixConfig {


    @Bean
    @ConfigurationProperties("spring.datasource.phoenix")
    public DataSource phoenixDataSource(){
        return new HikariDataSource();
    }

//    @Bean
//    public SqlSessionFactory phoenixSqlSessionFactory(@Qualifier("phoenixDataSource") @Autowired DataSource phoenixDataSource) throws Exception {
//
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//        sqlSessionFactoryBean.setDataSource( phoenixDataSource() );
//
//        sqlSessionFactoryBean.setMapperLocations( new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/**/*.xml"));
//        //这里注入自己写的MybatisPlus SQL拦截器 可以不写
////        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
////        interceptor.addInnerInterceptor( new PhoenixMPPlugin() );
//
////        sqlSessionFactoryBean.setPlugins( interceptor );
//
//        MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
//        mybatisConfiguration.setMapUnderscoreToCamelCase(true);
//        mybatisConfiguration.setLogImpl(StdOutImpl.class);
//
//        sqlSessionFactoryBean.setConfiguration(mybatisConfiguration);
//        return sqlSessionFactoryBean.getObject();
//    }


//    @Bean
//    public SqlSessionTemplate phoenixSqlSessionTemplate(@Qualifier("phoenixSqlSessionFactory") @Autowired SqlSessionFactory phoenixSqlSessionFactory){
//        return new SqlSessionTemplate( phoenixSqlSessionFactory );
//    }
//
//    @Bean
//    public DataSourceTransactionManager phoenixDataSourceTransactionManager(@Qualifier("phoenixDataSource") @Autowired DataSource phoenixDataSource){
//        return new DataSourceTransactionManager(phoenixDataSource);
//    }


}
